#!/bin/bash
file_name=functions.sh
funcs=`which $file_name`
if [ "$funcs" != "" ] ;then
  echo "funcs=$funcs"
  . $funcs
else
  funcs=`dirname $0`/$file_name
  echo "$PWD"
  echo "funcs=$funcs"
  if [ "$funcs" != "" ] ;then
    . $funcs
  else
    exit
  fi
fi

#全局变量定义
download_dir=~/downloads/
download_dir_for_android=$download_dir/android/
download_dir_for_jdk=$download_dir_for_android/jdk/
download_dir_for_sdk=$download_dir_for_android/sdk/
download_dir_for_eclipse=$download_dir_for_android/eclipse/
download_dir_for_tools=$download_dir_for_android/tools/


function Initializing_the_Build_Environment()
{
  echoTextBlue "Initializing_the_Build_Environment ......"
  #32位系统需要安装的基础包
  android_base_32="git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils xsltproc"
  #64位系统需要安装的基础包
  android_base_64="git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc"
  if ! sh_system_is_i386; then
    sh_dpkg_install "$android_base_64"
  else
    sh_dpkg_install "$android_base_32"
  fi


}

function Download_source()
{
  echoTextBlue "Downloading_the_Source ......"
}

# Building and Running
# Building for Devices
# Building Kernels
# Known Issues

function Download_sdk()
{
    echoTextBlue "Downloading sdk ......"
sdk_list="
http://dl.google.com/android/installer_r18-windows.exe
http://dl.google.com/android/android-sdk_r18-windows.zip
http://dl.google.com/android/android-sdk_r18-linux.tgz
http://dl.google.com/android/android-sdk_r18-macosx.zip"
for sdk in $sdk_list
do 
  sh_wget $sdk  $download_dir_for_sdk
done
}

function Download_jdk()
{
#java-1.5.0-sun
java_1_5_0_sun="
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-bin_1.5.0-22-0ubuntu0.8.04_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-jre_1.5.0-22-0ubuntu0.8.04_all.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-jdk_1.5.0-22-0ubuntu0.8.04_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-plugin_1.5.0-22-0ubuntu0.8.04_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-demo_1.5.0-22-0ubuntu0.8.04_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-source_1.5.0-22-0ubuntu0.8.04_all.deb"
java_1_5_0_sun_64="
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-bin_1.5.0-22-0ubuntu0.8.04_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-jre_1.5.0-22-0ubuntu0.8.04_all.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-jdk_1.5.0-22-0ubuntu0.8.04_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-plugin_1.5.0-22-0ubuntu0.8.04_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-demo_1.5.0-22-0ubuntu0.8.04_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java5/sun-java5-source_1.5.0-22-0ubuntu0.8.04_all.deb"

#java-6-sun
java_6_sun="
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-bin_6.24-1build0.8.04.1_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-jre_6.24-1build0.8.04.1_all.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-jdk_6.24-1build0.8.04.1_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-plugin_6.24-1build0.8.04.1_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-demo_6.24-1build0.8.04.1_i386.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-source_6.24-1build0.8.04.1_all.deb"
java_6_sun_64="
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-bin_6.24-1build0.8.04.1_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-jre_6.24-1build0.8.04.1_all.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-jdk_6.24-1build0.8.04.1_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-plugin_6.24-1build0.8.04.1_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-demo_6.24-1build0.8.04.1_amd64.deb
http://mirror.globo.com/ubuntu/archive/pool/multiverse/s/sun-java6/sun-java6-source_6.24-1build0.8.04.1_all.deb"

for deb in $java_1_5_0_sun $java_1_5_0_sun_64
do 
  sh_wget $deb  $download_dir_for_jdk/java-1.5.0-sun_22
done
for deb in $java_6_sun $java_6_sun_64
do 
  sh_wget $deb  $download_dir_for_jdk/java-6-sun_24
done
}

function Setup-hack-tools()
{ 
echoTextBlue "安装反编译工具......"
local urls_list="
http://android-apktool.googlecode.com/files/apktool-install-linux-2.2_r01-1.tar.bz2
http://android-apktool.googlecode.com/files/apktool1.3.2.tar.bz2
http://laichao.googlecode.com/files/dex2jar-0.0.7-SNAPSHOT.zip
http://laichao.googlecode.com/files/jd-gui-0.3.2.linux.i686.tar.gz
http://android4me.googlecode.com/files/AXMLPrinter2.jar
"
for url in $urls_list
do
  sh_wget $url $download_dir_for_tools
done
mkdir -pv $download_dir_for_tools/out
for url in $urls_list
do
  ac_basename=`basename $url`
  if test -f $download_dir_for_tools/$ac_basename; then
    result=`file $download_dir_for_tools/$ac_basename |grep -E -w "gzip|bzip2"`
    if [ -n "$result" ]; then
      echoTextBlue "tar -xvf $download_dir_for_tools/$ac_basename -C $download_dir_for_tools/out"
      tar -xvf $download_dir_for_tools/$ac_basename -C $download_dir_for_tools/out
    fi
    result=`file $download_dir_for_tools/$ac_basename |grep -w Zip`
    if [ -n "$result" ]; then
      echoTextBlue "unzip $download_dir_for_tools/$ac_basename -d $download_dir_for_tools/out"
      unzip $download_dir_for_tools/$ac_basename  -d $download_dir_for_tools/out
    fi

  fi
done
  echoTextBlue "checkout apktool 源代码......"
  #svn checkout http://android-apktool.googlecode.com/svn/trunk/  ~/downloads/android-apktool-read-only
  return
}

function setup-eclipse-java-x()
{
    echoTextBlue "＊＊＊＊＊＊＊＊＊＊安装 eclipse-java-ganymede ＊＊＊＊＊＊＊＊＊＊＊＊＊"
    local ac_eclipse=helios
eclipse37_jee_indigo_SR2_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-linux-gtk.tar.gz
eclipse37_java_indigo_SR2_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/indigo/SR2/eclipse-java-indigo-SR2-linux-gtk.tar.gz
eclipse37_jee_indigo_SR2_64_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-linux-gtk-x86_64.tar.gz
eclipse37_java_indigo_SR2_64_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/indigo/SR2/eclipse-java-indigo-SR2-linux-gtk-x86_64.tar.gz
eclipse36_jee_helios_SR2_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/helios/SR2/eclipse-jee-helios-SR2-linux-gtk.tar.gz
eclipse36_java_helios_SR2_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/helios/SR2/eclipse-java-helios-SR2-linux-gtk.tar.gz
eclipse36_jee_helios_SR2_64_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/helios/SR2/eclipse-jee-helios-SR2-linux-gtk-x86_64.tar.gz
eclipse36_java_helios_SR2_64_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/helios/SR2/eclipse-java-helios-SR2-linux-gtk-x86_64.tar.gz
eclipse35_java_galileo_SR2_URL=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/galileo/SR2/eclipse-java-galileo-SR2-linux-gtk.tar.gz
keyword1="eclipse"
keyword2="URL"
menu_list=`sh_get_menu_list $keyword1 $keyword2`
  remote_eclipse=`sh_menu_select "$menu_list"`
  eval "remote_eclipse=\$$remote_eclipse"
  local_eclipse_name=`basename $remote_eclipse`
  local_eclipse=$download_dir_for_eclipse/$local_eclipse_name
  ac_eclipse=`echo $local_eclipse_name|sed 's/-linux-gtk.tar.gz//g'`
  mkdir $HOME/programes/ -p
  if test -f $local_eclipse; then
    echo "exist $local_eclipse"
  else
    sh_wget $remote_eclipse $download_dir_for_eclipse
    echo "not exist $local_eclipse"
  fi
 
  echo "$HOME/programes/$ac_eclipse"
  if test -d $HOME/programes/$ac_eclipse; then
    result=`question "是否覆盖已安装的 eclipse 版本：$HOME/programes/$ac_eclipse ?" 1 no`
    if [ "$result" = "yes" ]; then
      rm $HOME/programes/eclipse-java-$ac_eclipse -rf
      tar -xf  $local_eclipse -C $HOME/programes/
      mv $HOME/programes/eclipse $HOME/programes/$ac_eclipse
    fi
  else
    tar -xf  $local_eclipse -C $HOME/programes/
    mv $HOME/programes/eclipse $HOME/programes/$ac_eclipse
  fi
}

function Setup-eclipse()
{
    echoTextBlue "Begain to setup eclipse ......"
    echoTextBlue "Please select eclipse version"
    setup-eclipse-java-x
    echoTextRed "如果 eclipse 启动不正常，那么修改文件 ~/programes/eclipse-java-helios/eclipse.ini 内容：
--launcher.XXMaxPermSize
512m"
}
function Setup-adt-android-sdk()
{
    echoTextBlue "Begain to setup adt ......"
    echoTextBlue "run eclipse -> Help-> Software Updates 会弹出一个新窗口"
    echoTextBlue "Available Software-> Add Site..."
    echoTextBlue "在输入框的 Location 位置输入网址: http://dl-ssl.google.com/android/eclipse/site.xml"
    echoTextBlue "如果无法在线安装，请前往: http://developer.android.com/sdk/adt_download.html"
    echoTextBlue "In the Add Site dialog, click Archive."
    echoTextBlue "Browse and select the downloaded zip file:~/downloads/ADT_9.0.0.zip "
    echoTextBlue "Enter a name for the local update site (e.g., \"Android Plugin\") in the \"Name\" field"


    menu_list="
http://dl.google.com/android/android-sdk_r09-linux_x86.tgz
http://dl.google.com/android/ndk/android-ndk-r5b-linux-x86.tar.bz2
"
    echoTextBlue "Please select sdk or ndk ......"
    echoTextRed  "SDK Dependencies alsa-lib java-runtime libstdc++5 libxv ncurses openal sdl zlib"
    echoTextRed  "Required by android-apktool android-ndk android-ndk-crystax android-sdk-platform-tools eclipse-android"

    result=`sh_menu_select "$menu_list"`
    result=`echo "${result}"|tr ' ' '.'`
    echo "${result}"
    sh_wget ${result}  $download_dir_for_eclipse 
    if test -f $download_dir_for_eclipse`basename $result`; then
	tar -xf  $download_dir_for_eclipse/`basename $result` -C $HOME/programes/
    fi
}

function import-android-src-to-eclipse()
{
    cp development/ide/eclipse/.classpath ./ -rf
    chmod u+w .classpath
    echoTextBlue "在eclipse中新建Java工程，选择 \"Create project from existing source\"，然后选中android源文件根目录。单击完成即可。（这个过程可能需要几分钟，导入eclipse后将进行编译）"
}


function get-qualcomm-android-src-h()
{
echoTextBlue "
ac_root=/home/shared/qualcomm
ac_date=\`date +%Y%m%d\`
ac_branch=xxxxx
build_id=yyyyy
ac_xml=yyyyy.xml
mkdir -pv \$ac_root/\$ac_branch-\$build_id-\$ac_date
cd \$ac_root/\$ac_branch-\$build_id-\$ac_date
repo init -u git://codeaurora.org/platform/manifest.git -b \$ac_branch -m  \$ac_xml
nohup repo sync&
"

echoTextRed "
ac_url=http://smartphone/repositories/TD1014/trunk/
svn import integration-gingerbread_rel-M76XXTSNCJNLYA6150 $ac_url/gingerbread_rel-M76XXTSNCJNLYA6150  -m "导入 android 2.3" --no-ignore
"


}

function get-qualcomm-android-src()
{
remote_git_site=git://codeaurora.org/platform/manifest.git
remote_qcom_site=https://downloads.cdmatech.com/qdc
get-qualcomm-android-src-h
echo "Get qualcomm android source from https://www.codeaurora.org/xwiki/bin/QAEP/"
echo "Get qualcomm modem source from $remote_qcom_site BBKzhou1"
#====================================
#October 29, 2010 	 M76XXTSNCJNLYA6050 	 msm7627 	 froyo_almond 	 M76XXTSNCJNLYA6050.xml
#Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYA6050/HY11-N1188-6.zip
#Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYM6050/HY11-N1187-6.zip
    msm7227_android22_6050="M76XXTSNCJNLYA6050     froyo_almond      msm7627  20101029   HY11-N1188-6.zip M76XXTSNCJNLYM6050_HY11-N1187-6.zip"

#+++++++
#Documents and Downloads/Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYA7020/HY11-N2101-4.zip
#Documents and Downloads/Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYA7030/HY11-N2101-6.zip
#Documents and Downloads/Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYA7040/HY11-N2101-7.zip
#Documents and Downloads/Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYA7050/HY11-N2101-8.zip
#+++++++

#February 25, 2011 	 M76XXTSNCJNLYA7060 	 msm7627_7x 	 froyo 	 M76XXTSNCJNLYA7060.xml
#Documents and Downloads/Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYA7060/HY11-N2101-9.zip
#Documents and Downloads/Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYM7060/HY11-N2100-9.zip
    msm7227_android22_7060="M76XXTSNCJNLYA7060     froyo             msm7627_7x 20110225 HY11-N2101-9.zip M76XXTSNCJNLYM7060_HY11-N2100-9.zip"



#August 25, 2011 	 M76XXTSNCJNLYA6190 	 msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA6190.xml
   msm7227_android23_6190="M76XXTSNCJNLYA6190      gingerbread_rel  msm7627    20110825 HY11-N6258-2.zip   M76XXTSNCJNLYM6190_HY11-N6257-2.zip"

#July 11, 2011 	 M76XXTSNCJNLYA61801001 	 msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA61801001.xml
msm7227_android23_61801001="M76XXTSNCJNLYA61801001  gingerbread_rel  msm7627    20110711 "

#June 21, 2011 	 M76XXTSNCJNLYA6180 	 msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA6180.xml
#Documents and Downloads/Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYM6180
    msm7227_android23_6180="M76XXTSNCJNLYA6180      gingerbread_rel  msm7627    20110621  HY11-N6258-1.zip   M76XXTSNCJNLYM6180_HK11-N6257-1.zip "

#May 27, 2011 	 M76XXTSNCJNLYA6170 	 msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA6170.xml
    msm7227_android23_6170="M76XXTSNCJNLYA6170      gingerbread_rel  msm7627    20110527"


#May 18, 2011 	 M76XXTSNCJNLYA61601002 	   msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA61601002.xml
msm7227_android23_61601002="M76XXTSNCJNLYA61601002 gingerbread_rel   msm7627    20110518 HY11-N3863-5.zip M76XXTSNCJNLYM6150_HY11-N3862-5.zip"
#May 06, 2011 	 M76XXTSNCJNLYA61601001 	 msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA61601001.xml
msm7227_android23_61601001="M76XXTSNCJNLYA61601001 gingerbread_rel   msm7627    20110506 HY11-N3863-5.zip M76XXTSNCJNLYM6150_HY11-N3862-5.zip"
# April 11, 2011 	 M76XXTSNCJNLYA6160 	   msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA6160.xml
    msm7227_android23_6160="M76XXTSNCJNLYA6160     gingerbread_rel   msm7627    20110411 HY11-N3863-5.zip M76XXTSNCJNLYM6150_HY11-N3862-5.zip"
#March 22, 2011 	 M76XXTSNCJNLYA6150 	   msm7627 	 gingerbread_rel 	 M76XXTSNCJNLYA6150.xml
#Library/7x27/SW/MSM7x27 Linux/Release/M76xxTSNCJNLYA6150/HY11-N3863-5.zip
#Library/7x27/SW/MSM7x27 Linux/Release/M76XXTSNCJNLYM6150/HY11-N3862-5.zip
    msm7227_android23_6150="M76XXTSNCJNLYA6150     gingerbread_rel   msm7627    20110322 HY11-N3863-5.zip M76XXTSNCJNLYM6150_HY11-N3862-5.zip"
#====================================

#August 12, 2011 	 M7630AABBQMLZA404018 	 msm7630 	 gingerbread_rel 	 M7630AABBQMLZA404018.xml
  msm7630_android23_404018="M7630AABBQMLZA404018   gingerbread_rel   msm7630    20110812 HY11-N3520-4.zip M7630AABBQMAZM4040/HY11-N3519-4.zip"


#April 07, 2011   M7630AABBQMLZA404006 	 msm7630 	 gingerbread_rel M7630AABBQMLZA404006.xml
#Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMLZA4040/HY11-N3520-4.zip
#Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMAZM4040/HY11-N3519-4.zip
  msm7230_android23_404006="M7630AABBQMLZA404006   gingerbread_rel   msm7630    20110407 HY11-N3520-4.zip M7630AABBQMAZM4040/HY11-N3519-4.zip"

#February 24, 2011 	 M7630AABBQMLZA4040 	 msm7630 	 gingerbread_rel 	 M7630AABBQMLZA4040.xml
#Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMLZA4040/HY11-N3520-4.zip
#Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMAZM4040/HY11-N3519-4.zip
    msm7230_android23_4040="M7630AABBQMLZA4040     gingerbread_rel   msm7630    20110224 HY11-N3520-4.zip M7630AABBQMAZM4040_HY11-N3519-4.zip"

#May 05, 2011 	 M7630AABBQMLZA404010 	 msm7630 	 gingerbread_rel 	 M7630AABBQMLZA404010.xml
#Documents and Downloads/Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMLZA404010/HY11-N3520-5.zip
#Documents and Downloads/Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMAZM404010/HY11-N3519-5.zip
  msm7230_android23_404010="M7630AABBQMLZA404010   gingerbread_rel   msm7630    20110505 HY11-N3520-5.zip M7630AABBQMLZA404010_HY11-N3519-5.zip"

#May 20, 2011 	 M7630AABBQMLZA404011 	 msm7630 	 gingerbread_rel 	 M7630AABBQMLZA404011.xml
  msm7230_android23_404011="M7630AABBQMLZA404011   gingerbread_rel   msm7630    20110520 "
#June 02, 2011 	 M7630AABBQMLZA404012 	 msm7630 	 gingerbread_rel 	 M7630AABBQMLZA404012.xml
  msm7230_android23_404012="M7630AABBQMLZA404012   gingerbread_rel   msm7630    20110602 "


#April 01, 2011   M7630AABBQMLZA4125 	 msm7630 	 gingerbread 	 M7630AABBQMLZA4125.xml
#Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMLZA4125/HY11-N4406-2.zip
#Library/7x30/SW/MSM7x30 Linux/Release/M7630AABBQMAZM4125/HY11-N4405-2.zip
    msm7230_android23_4125="M7630AABBQMLZA4125     gingerbread       msm7630    20110401 HY11-N4406-2.zip M7630AABBQMAZM4125_HY11-N4405-2.zip"
#May 31, 2011 	 M7630AABBQMLZA4151 	 msm7630 	 gingerbread_house 	 M7630AABBQMLZA4151.xml
    msm7230_android23_4151="M7630AABBQMLZA4151     gingerbread_house msm7630    20110531"


##
ac_list="qcsblhd_cfgdata partition oemsblhd appsboothd qcsbl oemsbl amss"

menu_list="
msm7227_android22_6050
msm7227_android22_7060
msm7227_android23_6150
msm7227_android23_6160
msm7227_android23_61601001
msm7227_android23_61601002
msm7227_android23_6170
msm7227_android23_6180
msm7227_android23_61801001
m1sm7227_android23_6190
msm7230_android23_4040
msm7230_android23_404006
msm7230_android23_404010
msm7230_android23_404011
msm7230_android23_404012
msm7630_android23_404018
msm7230_android23_4125
msm7230_android23_4151
"
for menu in $menu_list
do
eval "menu=\$$menu"
echoTextRed "$menu"
done
echoTextBlue "Please select"
result=`sh_menu_select "$menu_list"`
eval "result=\$$result"
echo "result=$result"
ac_root=/home/shared/qualcomm
ac_date=`echo $result|awk '{print $4}'`
ac_chipset=`echo $result|awk '{print $3}'`
ac_branch=`echo $result|awk '{print $2}'`
build_id=`echo $result|awk '{print $1}'`
ac_xml=`echo $result|awk '{print $1}'`.xml
vendor_file=`echo $result|awk '{print $5}'`
modem_file=`echo $result|awk '{print $6}'`
echoTextBlue "
从网站 $remote_git_site  下载 android 源代码
从网站 $remote_qcom_site 下载 mdoem 和 vendor 源码"
echoTextGreen "
========================================
 android version: $ac_branch
android build id: $build_id
  modem build id: $modem_file
          vendor: $vendor_file
========================================
"
result=`question "是否下载高通 android 源码 $build_id($ac_branch) for $ac_chipset?" 1 no`
if [ "$result" = "yes" ]; then
    REPO=`which repo`
    if [ -z "$REPO" ]; then
        echoTextRed "repo command not exist!!!"
	return
    fi
    ac_root=`question  "请指定源代码存放路径"  2  $ac_root`
    if test -d $ac_root/$ac_branch-$build_id-$ac_date; then
        result=`question "目录:$ac_root/$ac_branch-$build_id-$ac_date 已经存在，是否重新指定?" 1 yes`
        if [ "$result" = "no" ]; then
	    echo "$ac_root/$ac_branch-$build_id-$ac_date"
	    if test -d $ac_root/$ac_branch-$build_id-$ac_date/.repo; then
	        echo "$ac_root/$ac_branch-$build_id-$ac_date/.repo"
		#sh_repo_sync 
	        echo "nohup repo sync&"
	        nohup repo sync&
		return
            else
	        echoTextRed "$ac_root/$ac_branch-$build_id-$ac_date/.repo not exist!"
	        return
            fi
	fi
    fi
    mkdir -pv $ac_root/$ac_branch-$build_id-$ac_date
    cd $ac_root/$ac_branch-$build_id-$ac_date
    if [ -n "$remote_git_site" ] && [ -n "$ac_branch" ] && [ -n "$ac_xml" ]; then
        echo "repo init -u $remote_git_site -b $ac_branch -m  $ac_xml"
        repo init -u $remote_git_site -b $ac_branch -m  $ac_xml
    else
	echoTextRed "exst error!"
	return
    fi
fi
}


function get-google-android-src()
{

sh_dpkg_install "curl"
sh_check-repo
#local ac_date=`echo $result|awk '{print $4}'`
remote_git_site=git://android.git.kernel.org/platform/manifest.git
#repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake     #Android1.5的代码分支
#repo init -u git://android.git.kernel.org/platform/manifest.git -b donut       #Android1.6的代码分支
#repo init -u git://android.git.kernel.org/platform/manifest.git -b eclair      #Android2.0.1和2.1的代码分支
#repo init -u git://android.git.kernel.org/platform/manifest.git -b froyo       #Android2.2的代码分支
menu_list="
cupcake
donut
eclair
froyo
gingerbread
setup-trac.sh"
echoTextBlue "Please select"
result=`sh_menu_select "$menu_list"`
echo "${result}"
${result}

remote_git_site=git://android.git.kernel.org/platform/manifest.git
ac_root=`pwd`
ac_branch=${result}


if [ -n "$remote_git_site" ] && [ -n "$ac_branch" ]; then
  mkdir -pv $ac_root/$ac_branch-$ac_date
  cd $ac_root/$ac_branch-$ac_date
  echo "repo init -u $remote_git_site -b $ac_branch"
  #repo init -u $remote_git_site -b $ac_branch
  #repo_sync
else
  echoTextRed "exst error!"
  return
fi
}



#脚步入口：解析参数
while test $# != 0
do
    case $1 in
	-r)
	    shift
	    version=$1
	    ;;
	-m)
	    shift
	    mode=$1
	    ;;
        *)
	    mode=$1
	    ;;
       esac
       shift
done

if [ "$mode" == "auto" ]; then
    echo "auto"
    setup-android-base
    setup-jdk
    setup-eclipse
    setup-adt-android-sdk
else
    menu_list="
Initializing_the_Build_Environment
Download_sdk
Download_jdk
Download_eclipse
Download_source
Setup-sdk
Setup-jdk
Setup-eclipse
setup-adt-android-sdk
Setup-hack-tools
import-android-src-to-eclipse
get-qualcomm-android-src
get-google-android-src
"
    echoTextBlue "Please select"
    result=`sh_menu_select "$menu_list"`
    echo "${result}"
    ${result}
fi
